package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class StrategyDetail {
    public static final int STATE_NORMAL = 0;   //草稿
    public static final int STATE_RELEASE = 1;  //发布
    private Long id;    //id

    private String title;   //标题
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime;    //创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;   //发布时间

    private Integer sequence;   //排序

    private StrategyCatalog catalog;    //攻略类别

    private String coverUrl;    //封面

    private Integer state;  //状态

    private StrategyContent strategyContent;    //攻略内容


    public String getStateDisplay(){
        if(state == STATE_NORMAL){
            return "未发布";
        }else if(state == STATE_RELEASE){
            return "已发布";
        }
        return "";
    }

    public String getJsonString(){
        Map<String, Object> map = new HashMap<>();

        map.put("id",id);
        map.put("title",title);
        map.put("releaseTime",releaseTime);
        if(catalog!=null){
            map.put("catalogId",catalog.getId());
            map.put("strategyId",catalog.getStrategyId());
        }
        map.put("coverUrl",coverUrl);
        map.put("sequence",sequence);
        map.put("state",state);
        if (strategyContent!=null){
            map.put("content",strategyContent.getContent());
        }
        return JSONUtils.toJSONString(map);
    }
}